namespace XRM.Security.DataAccess.Context
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class RequestChange1 : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.RequestCert",
                c => new
                    {
                        RequestCertId = c.Int(nullable: false, identity: true),
                        FileName = c.String(nullable: false, maxLength: 255),
                        FileData = c.Binary(),
                        UserRegisterId = c.Int(nullable: false),
                        IdentityCenterId = c.Int(nullable: false),
                        PCId = c.Int(),
                        UploadDate = c.DateTime(nullable: false),
                        FromDate = c.DateTime(nullable: false),
                        ToDate = c.DateTime(nullable: false),
                        SerialNumber = c.String(nullable: false, maxLength: 50),
                        SerialNumberEtoken = c.String(nullable: false, maxLength: 50),
                        Thumbprint = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.RequestCertId)
                .ForeignKey("dbo.IdentityCenter", t => t.IdentityCenterId, cascadeDelete: true)
                .ForeignKey("dbo.PC", t => t.PCId)
                .ForeignKey("dbo.UserRegister", t => t.UserRegisterId, cascadeDelete: true)
                .Index(t => t.UserRegisterId)
                .Index(t => t.IdentityCenterId)
                .Index(t => t.PCId);
            
            CreateTable(
                "dbo.RequestCertInfoSystem",
                c => new
                    {
                        RequestCertId = c.Int(nullable: false),
                        InfoSystemId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.RequestCertId, t.InfoSystemId })
                .ForeignKey("dbo.InfoSystem", t => t.InfoSystemId, cascadeDelete: true)
                .ForeignKey("dbo.RequestCert", t => t.RequestCertId, cascadeDelete: true)
                .Index(t => t.RequestCertId)
                .Index(t => t.InfoSystemId);
            
            AddColumn("dbo.RequestWorkKindParam", "RequestCertId", c => c.Int());
            CreateIndex("dbo.RequestWorkKindParam", "RequestCertId");
            AddForeignKey("dbo.RequestWorkKindParam", "RequestCertId", "dbo.RequestCert", "RequestCertId");
            DropColumn("dbo.RequestWorkKindParam", "FileName");
            DropColumn("dbo.RequestWorkKindParam", "FileData");
            DropColumn("dbo.RequestWorkKindParam", "IdentityCenterId");
            DropColumn("dbo.RequestWorkKindParam", "UploadDate");
            DropColumn("dbo.RequestWorkKindParam", "FromDate");
            DropColumn("dbo.RequestWorkKindParam", "ToDate");
            DropColumn("dbo.RequestWorkKindParam", "SerialNumber");
            DropColumn("dbo.RequestWorkKindParam", "SerialNumberEtoken");
            DropColumn("dbo.RequestWorkKindParam", "Thumbprint");
        }
        
        public override void Down()
        {
            AddColumn("dbo.RequestWorkKindParam", "Thumbprint", c => c.String(maxLength: 50));
            AddColumn("dbo.RequestWorkKindParam", "SerialNumberEtoken", c => c.String(maxLength: 50));
            AddColumn("dbo.RequestWorkKindParam", "SerialNumber", c => c.String(maxLength: 50));
            AddColumn("dbo.RequestWorkKindParam", "ToDate", c => c.DateTime());
            AddColumn("dbo.RequestWorkKindParam", "FromDate", c => c.DateTime());
            AddColumn("dbo.RequestWorkKindParam", "UploadDate", c => c.DateTime());
            AddColumn("dbo.RequestWorkKindParam", "IdentityCenterId", c => c.Int());
            AddColumn("dbo.RequestWorkKindParam", "FileData", c => c.Binary());
            AddColumn("dbo.RequestWorkKindParam", "FileName", c => c.String(maxLength: 255));
            DropForeignKey("dbo.RequestWorkKindParam", "RequestCertId", "dbo.RequestCert");
            DropForeignKey("dbo.RequestCert", "UserRegisterId", "dbo.UserRegister");
            DropForeignKey("dbo.RequestCertInfoSystem", "RequestCertId", "dbo.RequestCert");
            DropForeignKey("dbo.RequestCertInfoSystem", "InfoSystemId", "dbo.InfoSystem");
            DropForeignKey("dbo.RequestCert", "PCId", "dbo.PC");
            DropForeignKey("dbo.RequestCert", "IdentityCenterId", "dbo.IdentityCenter");
            DropIndex("dbo.RequestCertInfoSystem", new[] { "InfoSystemId" });
            DropIndex("dbo.RequestCertInfoSystem", new[] { "RequestCertId" });
            DropIndex("dbo.RequestCert", new[] { "PCId" });
            DropIndex("dbo.RequestCert", new[] { "IdentityCenterId" });
            DropIndex("dbo.RequestCert", new[] { "UserRegisterId" });
            DropIndex("dbo.RequestWorkKindParam", new[] { "RequestCertId" });
            DropColumn("dbo.RequestWorkKindParam", "RequestCertId");
            DropTable("dbo.RequestCertInfoSystem");
            DropTable("dbo.RequestCert");
        }
    }
}
